<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class Papper extends Base
{
    use SoftDeletes;

    /**
     * 文件夹（一对一关系）
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function folder() {
        return $this->belongsTo(Folder::class);
    }

    /**
     * 文案标题（一对一关系）
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function title() {
        return $this->hasOne(PapperTitle::class);
    }
    
    /**
     * 账号（一对一关系）
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function account() {
        return $this->belongsTo(Account::class);
    }
    public function ip() {
        return $this->belongsTo(Ip::class);
    }
    
    public function user() {
        return $this->belongsTo(User::class);
    }

    /**
     * 音频（一对多关系）
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function audios() {
        return $this->hasMany(Audio::class);
    }

    /**
     * 任务（一对多关系）
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function tasks() {
        return $this->hasMany(Task::class)
            ->select(['id', 'status', 'papper_id', 'type']);
    }

    /**
     * 镜头组（一对多关系）
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function footages() {
        return $this->hasMany(Footage::class);
    }

    /**
     * 文案要求（一对一关系）
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function need() {
        return $this->hasOne(PapperNeed::class);
    }
    
    public function video() {
        return $this->hasOne(TaskFile::class)->where('type', 2);
    }
}
